package com.jt.tenant.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.Get4SShopList;
import com.jt.tenant.widget.Tools;

import java.util.List;


/**
 * Created by Administrator on 2016/2/16.
 */
public class MaintainAdapter extends BaseAdapter {

    private LayoutInflater layoutInflater;

    private List<Get4SShopList.FSList> list;

    public MaintainAdapter(Context context, List<Get4SShopList.FSList> list) {

        layoutInflater = ((Activity) context).getLayoutInflater();

        this.list = list;

    }

    @Override
    public int getCount() {

        return list.size();

    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

        if (convertView == null) {

            convertView = JTApplication.ScaleScreenHelper.loadView((ViewGroup) layoutInflater.inflate(R.layout.item_maintain, null));

            holder = new ViewHolder();

            holder.item_name = (TextView) convertView.findViewById(R.id.text_item_name);

            holder.item_address = (TextView) convertView.findViewById(R.id.text_item_address);

            holder.item_dis = (TextView) convertView.findViewById(R.id.text_item_dis);

            holder.item_img = (ImageView) convertView.findViewById(R.id.img_item_maintain);

            convertView.setTag(holder);

        } else {

            holder = (ViewHolder) convertView.getTag();

        }
        if (!list.get(position).LOGO.equals("")) {
            JTApplication.UtilAsyncBitmap.get(list.get(position).LOGO, holder.item_img);
        }

        holder.item_name.setText(list.get(position).NAME);

        holder.item_address.setText(list.get(position).ADDRESS);

        holder.item_dis.setText("距离当前位置 ：约"+ Tools.F_num(String.valueOf(list.get(position).DISTANCE/1000))+"km");

        return convertView;

    }

    private class ViewHolder {

        private TextView item_name;

        private TextView item_address;

        private TextView item_dis;

        private ImageView item_img;
    }

}
